package LanQiao._13JavaB;

import java.util.HashSet;
import java.util.Scanner;

//WA  暴力dfs  40%
public class _7数组切分 {
    static int count = 0;
    static int mod = 1000000007;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        dfs1(0, 1, arr);
        System.out.println(count);
        scan.close();
    }

    public static void dfs(int left, int right, int[] arr) {
        int n = arr.length;
        if (right == n) {
            boolean helper = helper(left, right, arr);
            if (helper) {
                count++;
                count = count % mod;
            }
            return;
        }
        while (right < n) {
            dfs(right, right + 1, arr);
            right++;
            while (right < n && !helper(left, right, arr)) {
                right++;
            }
            if (right == n) {
                boolean helper = helper(left, right, arr);
                if (helper) {
                    count++;
                    count = count % mod;
                }
            }
        }
    }

    //切记，别把回溯和dfs搞混了
    public static void dfs1(int left, int right, int[] arr) {
        int n = arr.length;
        if (right == n) {
            boolean helper = helper(left, right, arr);
            if (helper) {
                count++;
                count = count % mod;
            }
            return;
        }
        dfs1(right, right + 1, arr);
        right++;
        while (right < n && !helper(left, right, arr)) {
            right++;
        }
        dfs1(left, right, arr);
    }

    public static boolean helper(int left, int right, int[] arr) {
        HashSet<Integer> set = new HashSet<>();
        int max = Integer.MIN_VALUE;
        for (int i = left; i < right; i++) {
            set.add(arr[i]);
            max = Math.max(max, arr[i]);
        }
        int n = set.size();
        for (int i = 0; i < n; i++) {
            boolean contains = set.contains(max);
            if (!contains) {
                return false;
            }
            max--;
        }
        return true;
    }

    /*
    他解
    方法：DP
    定义: dp[i]表示以i为结尾的分法有多少种
    技巧：如何判断区间[i,j]是否可以组成一段连续的自然数？
        只需区间最大值 - 区间最小值 == j - i (区间长度)即可

    思路：这里设两层循环，一层i表示左端点，第二层j表示右端点。
        因为是连续的所以在所取的[l，r]范围中寻找最大值，最小值。
        然后相减，最后和r-l（区间长度）作比较即可。
     */
    public class Soulution {
        static int mod = 1000000007;

        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int[] a = new int[n + 1];
            for (int i = 1; i <= n; i++) a[i] = scan.nextInt();
            //dp[i]：以a[i]结尾的切分合法数组的方法数量
            int[] dp = new int[n + 1];
            dp[0] = 1;//初始化
            for (int i = 1; i <= n; i++) {
                int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;//注意初始化：max是小的，min是大的
                for (int j = i; j > 0; j--) {
                    max = Math.max(max, a[j]);
                    min = Math.min(min, a[j]);
                    if (max - min == i - j) dp[i] = (dp[i] + dp[j - 1]) % mod;
                }
            }
            System.out.println(dp[n]);
        }
    }
}
